// pages/search_results_page.dart
import 'package:flutter/material.dart';
import 'package:cesi/model/Coffee.dart';
import 'package:cesi/components/coffee_tile.dart';
import 'package:cesi/theme/color.dart';

class SearchResultsPage extends StatelessWidget {
  final String searchQuery;
  final List<Coffee> searchResults;
  final Function(Coffee) onCoffeeTap;

  const SearchResultsPage({
    super.key,
    required this.searchQuery,
    required this.searchResults,
    required this.onCoffeeTap,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.cream,
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        foregroundColor: AppColors.textDark,
        elevation: 0,
        leading: IconButton(
          icon: Icon(Icons.arrow_back, color: AppColors.primaryBrown),
          onPressed: () => Navigator.pop(context),
        ),
        title: Text(
          '搜索结果',
          style: TextStyle(
            color: AppColors.textDark,
            fontWeight: FontWeight.bold,
          ),
        ),
      ),
      body: Column(
        children: [
          // 搜索信息
          Padding(
            padding: const EdgeInsets.all(16.0),
            child: Text(
              "搜索: \"$searchQuery\"",
              style: TextStyle(fontSize: 16, color: AppColors.textLight),
            ),
          ),

          // 搜索结果数量
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16.0),
            child: Row(
              children: [
                Text(
                  "找到 ${searchResults.length} 个结果",
                  style: TextStyle(color: AppColors.textLight, fontSize: 14),
                ),
              ],
            ),
          ),

          const SizedBox(height: 16),

          // 搜索结果列表
          Expanded(
            child: searchResults.isEmpty
                ? Center(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Icon(
                          Icons.search_off,
                          size: 64,
                          color: AppColors.lightBrown,
                        ),
                        const SizedBox(height: 16),
                        Text(
                          "没有找到相关商品",
                          style: TextStyle(
                            fontSize: 18,
                            color: AppColors.textLight,
                          ),
                        ),
                        const SizedBox(height: 8),
                        Text(
                          "请尝试其他关键词",
                          style: TextStyle(
                            fontSize: 14,
                            color: AppColors.textLight,
                          ),
                        ),
                      ],
                    ),
                  )
                : ListView.builder(
                    padding: const EdgeInsets.symmetric(horizontal: 16),
                    itemCount: searchResults.length,
                    itemBuilder: (context, index) {
                      final coffee = searchResults[index];
                      return Container(
                        margin: const EdgeInsets.only(bottom: 12),
                        child: CoffeeTile(
                          coffee: coffee,
                          onTap: () => onCoffeeTap(coffee),
                        ),
                      );
                    },
                  ),
          ),
        ],
      ),
    );
  }
}
